<?php
/**
 * @package Autogenerator for Joomla!
 * @version 3.0.0
 * @author Truong Cong Duc <truongcongduc4@gmail.com>
 * @link autogenerator.blogspot.com
 * @copyright (c) 2013, Truong Cong Duc
 * @license GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JLoader::register('AutogeneratorHtmlTable', AUTOGENERATOR_DIR_ROOT . '/lib/table.php');

class AutogeneratorViewMvcs extends JViewLegacy {

    protected $items;
    protected $pagination;
    protected $state;

    public function display($tpl = null) {
        AutogeneratorHelper::addSubmenu('mvcs');

        $this->items = $this->get('Items');
        $this->pagination = $this->get('Pagination');
        $this->state = $this->get('State');

        $this->addToolbar();

        $this->addFilter();

        parent::display($tpl);
    }

    protected function addToolbar() {
        JToolbarHelper::title(JText::_('COM_AUTOGENERATOR_MVCS_TITLE'));

        JToolbarHelper::addNew('mvc.add');
        JToolbarHelper::editList('mvc.edit');
        JToolbarHelper::deleteList(JText::_('COM_AUTOGENERATOR_MESSAGE_CONFIRM_DELETE'), 'mvcs.delete', 'JTOOLBAR_DELETE');
    }

    protected function addFilter() {
        JHtmlSidebar::setAction('index.php?option=com_autogenerator&view=mvcs');

        // Add filter.
        JHtmlSidebar::addFilter(JText::_('COM_AUTOGENERATOR_TABLES_SELECT_COMPONENT'), 'filter_component_id', JHtml::_('select.options', AutogeneratorHtmlTable::options(), 'value', 'text', $this->state->get('filter.component_id')));

        $this->sidebar = JHtmlSidebar::render();
    }

    protected function getSortFields() {
        return array(
            'am.id' => JText::_('JGRID_HEADING_ID')
        );
    }

}
